// pages/person/myService/index.js
const ajax = require('../../../utils/quest.js');
const util = require('../../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShow: 1,
    limit: 10,
    page: 1,
    dataList: [],
    serviceList: [],
    totalPage: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getList()
  },
  releaseDemand() {
    wx.navigateTo({
      url: '/pages/person/releaseService/index',
    })
  },
  getList() {
    const data = {
      page: this.data.page,
      limit: this.data.limit,
    }
    let params = util.setQueryConfig(data)
    ajax.sendRequest('/provideService/list?' + params, 'get', ).then(res => {
      const dataList = this.data.dataList
      const list = res.data.page.list
      for (var i = 0; i < list.length; i++) {
        dataList.push(list[i]);
      }
      //后台返回的列表的总页数 
      const totalPage = res.data.page.totalPage
      this.setData({
        serviceList: dataList,
        ifHaveMore: true,
        totalPage: totalPage
      })
    })
  },
  deleteList(e) {
    const that = this
    const id = e.currentTarget.dataset.id
    wx.showModal({
      title: '提示',
      content: '确定要删除吗？',
      success: function (res) {
        if (res.confirm) {
          that.delCurrentData(id)
        } else if (res.cancel) {
          console.log('点击取消了');
          return false;
        }
      }
    })
  },
  delCurrentData(id) {
    const that = this
    ajax.sendRequest('/provideService/delete/' + id, 'get').then(res => {
      console.log("热", res);
      if (res.data.code == 0) {
        wx.showLoading({
          title: '删除成功',
        })
        this.setData({
          serviceList: []
        })
        that.getList()
      }
    })
  },
  bandDetail(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/person/releaseService/index?id=' + id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const {
      ifHaveMore
    } = this.data
    if (ifHaveMore) {
      this.setData({
        page: this.data.page + 1
      })
      this.getList()
    } else {
      wx.showToast({
        title: '暂无更多数据',
        icon: "none"
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})